<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace App\Setting;

use App\Base\BaseForm;
use App\Base\ViewsInList;
use App\Model\GradeCategoryModel;
use App\Model\LazyCommon\CCM;
use App\Model\SubjectModel;
use App\Model\TeacherModel;

class LiveSetting{

    /*手动获取的配置项*/
    public $catType = "level";//Options:level snake
    public $entityCnName = "直播课程";//模块名称
    public $table = "Live";//数据表名称
    public $editKeys = array('id','title','grade_Id','subject_Id','teacher_Id','startdate','enddate','tips','pic','url','scan','intro','content','isTop','isHot','isOn','addtime','updatetime');//后台管理列表中可以直接编辑的字段
    public $perPage = 100;//后台管理列表中可以直接编辑的字段

    /*自动获取的配置项*/
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $entity;
    public $modelPath;
    public $doctrine;
    public $em;

    public function __construct($doctrine)
    {
        $this->bundleName = "App";
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        //$this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",__CLASS__));
        $this->entityPath = "App\\Entity\\".$this->entityName;
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->doctrine = $doctrine;
        $this->em = $doctrine->getManager();
    }

    public function listConfig()
    {
        $default = array();
        $default["Live AS Live"]["select"] = array('id','title','grade_Id','subject_Id','teacher_Id','startdate','enddate','tips','pic','url','scan','intro','content','time','is_Top','is_Hot','is_On','addtime','updatetime');
        $default["Live AS Live"]["search"] = array('id','title','grade_Id','subject_Id','teacher_Id','startdate','enddate','tips','pic','url','scan','intro','content','is_Top','is_Hot','is_On','addtime','updatetime');
        $default["Live AS Live"]["condition"] = array('id','title','grade_Id','subject_Id','teacher_Id','startdate','enddate','tips','pic','url','scan','intro','content','is_Top','is_Hot','is_On','addtime','updatetime');
        $default["Live AS Live"]["orderBy"] = array('id','title','grade_Id','subject_Id','teacher_Id','startdate','enddate','tips','pic','url','scan','intro','content','is_Top','is_Hot','is_On','addtime','updatetime');

        $join = array();
        $join["Grade_Category AS Grade"]["on"] = "Grade.id = Live.grade_Id";
        $join["Grade_Category AS Grade"]["select"] = array("name");
        $join["Grade_Category AS Grade"]["search"] = array();
        $join["Grade_Category AS Grade"]["condition"] = array();
        $join["Grade_Category AS Grade"]["orderBy"] = array();

        $join["Subject AS Subject"]["on"] = "Subject.id = Live.subject_Id";
        $join["Subject AS Subject"]["select"] = array("name");
        $join["Subject AS Subject"]["search"] = array();
        $join["Subject AS Subject"]["condition"] = array();
        $join["Subject AS Subject"]["orderBy"] = array();

        $join["Teacher AS Teacher"]["on"] = "Teacher.id = Live.teacher_Id";
        $join["Teacher AS Teacher"]["select"] = array("name");
        $join["Teacher AS Teacher"]["search"] = array();
        $join["Teacher AS Teacher"]["condition"] = array();
        $join["Teacher AS Teacher"]["orderBy"] = array();
//        $join["LiveCategory"]["on"] = "";
//        $join["LiveCategory"]["select"] = array();
//        $join["LiveCategory"]["search"] = array();
//        $join["LiveCategory"]["condition"] = array();
//        $join["LiveCategory"]["orderBy"] = array();


        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function viewConfig()
    {

    }


    public function formConfig()
    {
        $BaseForm = new BaseForm();
        
        $config["title"] = $BaseForm->text("title","标题");
//        $config["gradeId"] = $BaseForm->text("gradeId","gradeid");
//        $config["subjectId"] = $BaseForm->text("subjectId","subjectid");
//        $config["teacherId"] = $BaseForm->text("teacherId","teacherid");
        $CCM = new CCM($this->doctrine);
        $GradeCategoryModel = new GradeCategoryModel($this->doctrine);
        $data = $GradeCategoryModel->getAllGradeCategoryTree();
        $grade = $CCM->createSelectFromCategoryTree($data);
        $config["gradeId"] = $BaseForm->select("gradeId","年级",$grade)->enableFind();

        $SubjectModel = new SubjectModel($this->doctrine);
        $data = $SubjectModel->getAll();
        $subject = $CCM->createSelectFromEntity($data);
        $config["subjectId"] = $BaseForm->select("subjectId","科目",$subject);

        $TeacherModel = new TeacherModel($this->doctrine);
        $data = $TeacherModel->getAll();
        $teacher = $CCM->createSelectFromEntity($data);
        $config["teacherId"] = $BaseForm->select("teacherId","教师",$teacher)->enableFind();
        $config["startdate"] = $BaseForm->date("startdate","开始日期");
        $config["enddate"] = $BaseForm->date("enddate","结束日期");
        $config["time"] = $BaseForm->time("time","上课时间");
        $config["tips"] = $BaseForm->text("tips","授课形式");
        $config["price"] = $BaseForm->text("price","课程价格")->ruleNotNull();
        $config["pic"] = $BaseForm->pic("pic","封面图片");
        $config["url"] = $BaseForm->textarea("url","直播地址");
        $config["scan"] = $BaseForm->textarea("scan","试听地址");
        $config["intro"] = $BaseForm->textarea("intro","教学目标");
        $config["content"] = $BaseForm->article("content","课程介绍");
        $isTopData[0] = "否";
        $isTopData[1] = "是";
        $config["isTop"] = $BaseForm->radio("isTop","是否置顶",$isTopData);
        $isHotData[0] = "否";
        $isHotData[1] = "是";
        $config["isHot"] = $BaseForm->radio("isHot","是否热门",$isHotData);
        $isOnData[0] = "否";
        $isOnData[1] = "是";
        $config["isOn"] = $BaseForm->radio("isOn","是否开放",$isOnData);
//        $config["addtime"] = $BaseForm->text("addtime","创建时间");
//        $config["updatetime"] = $BaseForm->text("updatetime","updatetime");
        return $config;
    }
}